package me.luger.project.fof.controller.api;

import com.alibaba.fastjson.JSONObject;
import me.luger.core.commom.util.JsonUtil;
import me.luger.core.commom.util.LogUtil;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.project.fof.service.FofParamHistoyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * FofParamHistoy controller
 */
@Controller
@RequestMapping("/api/fof/fofParamHistoy")
public class FofParamHistoyApiController extends BaseController {

    @Autowired
    private FofParamHistoyService fofParamHistoyService;

    @RequestMapping(value = "/editFofParam",name = "获取fof编辑信息的接口")
    @ResponseBody
    public Object editFofParam(Integer fofId,
                               @RequestParam(defaultValue = "0") Integer step){
        try{
            String param = fofParamHistoyService.getLatestFofParam(fofId);
            if(null == param){
                return Result.error("未查到该FOF配置项");
            }
            JSONObject paramObj = JsonUtil.parse2JsonObject(param);
            if(step != 0){
                JSONObject stepJsonObj = paramObj.getJSONObject("step"+step);
                if(null == stepJsonObj){
                    return Result.error("未查到该FOF配置项");
                }
                return Result.success(stepJsonObj);
            }
            return Result.success(paramObj);
        }catch (Exception e){
            LogUtil.errorLog(e,"");
            return Result.error();
        }
    }

    @RequestMapping(value = "",name = "接口描述")
    @ResponseBody
    public Object demo(){
        try{

        }catch (Exception e){
            LogUtil.errorLog(e,"");
            return Result.error();
        }
        return Result.success();
    }
}
